package com.rattsoftware.server.serviceImpl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rattsoftware.server.admin.model.Course;
import com.rattsoftware.server.admin.model.exceptions.RattsSecurityException;
import com.rattsoftware.server.admin.model.paging.PagingLoadConfig;
import com.rattsoftware.server.admin.model.paging.PagingLoadResult;
import com.rattsoftware.server.dao.CourseDAO;
import com.rattsoftware.server.service.CourseService;

@Service("courseService")
@Transactional
public class CourseServiceImpl implements CourseService{

	@Autowired
	private CourseDAO courseDAO;
	private Logger log = LoggerFactory.getLogger(CourseServiceImpl.class);
	
	@Override
	public void deleteCourse(Course course) throws RattsSecurityException {
		log.debug("Deleting course " + course.getName());
		courseDAO.deleteCourse(course);
	}

	@Override
	public void deleteCourse(List<Integer> courseIds)
			throws RattsSecurityException {
				
	}

	@Override
	public Course getCourse(int courseId) throws RattsSecurityException {
		return courseDAO.getCourse(courseId);
	}

	@Override
	public PagingLoadResult<Course> getCourseList(PagingLoadConfig pagingLoadConfig) throws RattsSecurityException {
		return courseDAO.getCourseList(pagingLoadConfig);
	}

	@Override
	public Integer getCourseUnitCount(int courseId)
			throws RattsSecurityException {
		return null;
	}

	@Override
	public Course saveCourse(Course course) throws RattsSecurityException {
		courseDAO.saveCourse(course);
		return course;
	}

	@Override
	public void saveCourses(List<Course> courses) throws RattsSecurityException {
		for (Course course : courses) {
			saveCourse(course);
		}
	}

}
